package cn.tedu.weibo.service.Impl;

import cn.tedu.weibo.mapper.CommentMapper;
import cn.tedu.weibo.pojo.dto.CommentDTO;
import cn.tedu.weibo.pojo.entity.Comment;
import cn.tedu.weibo.pojo.vo.CommentVO;
import cn.tedu.weibo.service.ICommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class CommentServiceImpl implements ICommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public int insert(CommentDTO commentDTO,Long uid) {
        Comment comment = new Comment();
        comment.setUserId(uid);
        comment.setCreated(new Date());
        BeanUtils.copyProperties(commentDTO, comment);
        int res = commentMapper.insert(comment);

        return res;
    }

    @Override
    public List<CommentVO> selectByWeiboId(Long id) {
        return commentMapper.selectByWeiboId(id);
    }
}
